package com.ssm.web;

import com.ssm.Service.shopListService;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "shopListServlet",urlPatterns = "/shopList")
public class shopListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        System.out.println("请求购物车清单...");
        String name=request.getParameter("name");
//        System.out.println("name:"+name);

        shopListService shopListService=new shopListService();

        List<Object> objectList = shopListService.shopList(name);

//        for (Object object1 : objectList) {
//            Object[] o = (Object[]) object1;
//            for (Object object2 : o) {
//                System.out.println("商品：" + object2.toString());
//            }
//        }
        response.setContentType("text/html;charset=utf-8");

        JSONArray data=JSONArray.fromObject(objectList);

        PrintWriter writer=response.getWriter();
        writer.print(data);
        writer.close();

    }
}
